<template>
  <div class="login">
    <el-form
      :rules="rules"
      :model="loginData"
      ref="loginData"
      class="demo-ruleForm"
      label-width="100px"
    >
      <!-- <i class="el-icon-user"></i> -->
      <el-form-item prop="rfid" label="卡号">
        <el-input
          v-model="loginData.rfid"
          placeholder="请输入卡号或刷卡"
        ></el-input>
      </el-form-item>
      <br />
      <!-- <i class="el-icon-unlock"></i> -->
      <el-form-item prop="psw" label="密码">
        <el-input
          v-model="loginData.psw"
          placeholder="请输入密码"
          show-password
        ></el-input
      ></el-form-item>
      <br />
      <el-button type="primary" @click="login">登录</el-button>
    </el-form>
  </div>
</template>

<script>
import crypto from "crypto";
export default {
  data() {
    return {
      loginData: {
        rfid: "",
        psw: "",
      },
      rules: {
        rfid: [{ required: true, message: "请输入卡号", trigger: "blur" }],
        psw: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    login: function () {
      if (this.loginData.rfid && this.loginData.psw) {
        var md5 = crypto.createHash("md5");
        md5.update(this.loginData.psw); //需要加密的密码
        this.loginData.psw = md5.digest("hex"); //password 加密完的密码
        this.$store.dispatch("loginUser", this.loginData);
        this.$router.push("/home");
        //this.$store.dispatch("loginUser", this.loginData);
      } else {
        alert("请输入账号或密码");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  width: 400px;
  height: 350px;
  position: absolute;
  left: 35%;
  top: 30%;
  text-align: center;
}
.el-input,
.el-button,
.el-form-item {
  width: 250px;
}
.el-button {
  background: #d2e6f8;
  color: #409eff;
}
</style>
